<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>GoodsManger</title>
    <link href="css/base.css" type="text/css" rel="stylesheet">
    <link href="css/tab.css" type="text/css" rel="stylesheet">
    <link href="css/item.css" type="text/css" rel="stylesheet">
    <link href="css/item_do.css" type="text/css" rel="stylesheet">

    <link rel="stylesheet" type="text/css"
          href="plugin/jquery-easyui-1.3.3/themes/default/easyui.css">
    <link rel="stylesheet" type="text/css"
          href="plugin/jquery-easyui-1.3.3/themes/icon.css">
    <script type="text/javascript"
            src="plugin/jquery-easyui-1.3.3/jquery.min.js"></script>
    <script type="text/javascript"
            src="plugin/jquery-easyui-1.3.3/jquery.easyui.min.js"></script>
    <script type="text/javascript"
            src="plugin/jquery-easyui-1.3.3/locale/easyui-lang-zh_CN.js"></script>
</head>
<body style="margin:1px;margin-top: 3px;" id="ff">
<table id="dg"  class="easyui-datagrid" pagination="true" data-options="pageSize:4,pageList:[4,8,12]"
       rownumbers="true" fit="true"
       url="/goods/search"
       toolbar="#tb">
    <thead data-options="frozen:true">
    <tr>
        <th field="cb" checkbox="true" align="center"></th>
        <th field="id" width="10%" align="center" hidden="true">编号</th>
        <th field="goodsname" width="100%" align="center">名称</th>
        <th field="typename" width="100%" align="center" formatter="getTypename">商品类别</th>
        <th field="img1" width="150%" align="center" formatter="formatProPic">缩略图</th>
        <th field="price" width="100%" align="center">价格</th>
        <th field="inventory" width="100%" align="center">库存</th>
        <th field="userid" width="100%" align="center">卖家ID</th>
        <th field="createTime" width="100%" align="center">创建时间</th>
        <th field="status" width="100%" align="center" formatter="getStatus">状态</th>
        <th field="content" width="100%" align="center"
            formatter="formatHref">操作
        </th>
    </tr>
    </thead>
</table>
<div id="tb">

    <div>
        &nbsp;<span style="font-size: 15px;">名称：&nbsp;</span><input style="height: 20px;font-size: 15px" type="text" id="goodsname" size="20"
                              onkeydown="if(event.keyCode==13) searchGoods()"/>&nbsp; <a
            href="javascript:searchGoods()" class="easyui-linkbutton"
            iconCls="icon-search" plain="true">搜索</a>
    </div>
    <div style="margin-top: 10px;">
        <a href="javascript:refuseGood()" class="easyui-linkbutton"
           iconCls="icon-cancel" plain="false">驳回</a>
           <a
            href="javascript:agreeGood()"
            class="easyui-linkbutton" iconCls="icon-ok" >通过</a> 
            <a
            href="javascript:deleteGoods()" class="easyui-linkbutton"
            iconCls="icon-remove" plain="false">删除</a>
    </div>
    
</div>
<div id="dlg" class="easyui-dialog"
     style="width: 1000px;height:550px;padding: 10px 20px; position: relative; z-index:1000;"
     closed="true" buttons="#dlg-buttons">
    <form id="fm" method="post" enctype="multipart/form-data">
        <div style="padding-top:50px;  float:left; width:95%; padding-left:30px;">
            <div id="i_do_wrap">

                <div class="i_do_div rel">
                    <p class="i_do_tle r_txt abs font14">商品名称</p>
                    <input type="text" id="title" name="name" class="easyui-validatebox" required="true"
                           style="border:1px #9c9c9c solid;height:25px;"/>
                </div>
                <div class="i_do_div rel" id="picture"><p class="i_do_tle r_txt abs font14">图片</p>
                </div>
                <div id="pic11" style="display:none;" class="i_do_div rel">
                </div>
                <div class="i_do_div rel" id="i_no_sku_stock_wrap"><p class="i_do_tle r_txt abs font14">简介</p>
                    <input type="text" id="desc" name="desc" value="" required="true" class="easyui-validatebox"
                           style="border:1px #9c9c9c solid;height:25px;"/>
                    <input id="id" name="id" type="hidden" value="0">
                </div>
            </div>
        </div>
    </form>
</div>

<div id="dlg-buttons">
    <a href="javascript:savePicture()" class="easyui-linkbutton"
       iconCls="icon-ok">保存</a> <a href="javascript:closePictureDialog()"
                                   class="easyui-linkbutton" iconCls="icon-cancel">关闭</a>
</div>

</body>
<script type="text/javascript">
    var url = "${pageContext.request.contextPath}/product";
    var method;

    function searchGoods() {
        $("#dg").datagrid('load', {
            "goodsname": $("#goodsname").val(),
        });
    }

    /*删除*/
    function deleteGoods() {
        var selectedRows = $("#dg").datagrid('getSelections');
        if (selectedRows.length == 0) {
            $.messager.alert("系统提示", "请选择要删除的数据！");
            return;
        }
        var strIds = [];
        for (var i = 0; i < selectedRows.length; i++) {
            strIds.push(selectedRows[i].id);
        }
        var ids = strIds.join(",");
        $.messager.confirm("系统提示", "您确认要删除这<font color=red>"
                + selectedRows.length + "</font>条数据吗？", function (r) {
            if (r) {
                $.ajax({
                    type: "GET",//方法类型
                    dataType: "json",//预期服务器返回的数据类型
                    url: "/goods/delete/" + ids,//url
                    data: {},
                    success: function (result) {
                        console.log(result);//打印服务端返回的数据
                        if (result.resultCode == 200) {
                            $.messager.alert(
                                    "系统提示",
                                    "数据已成功删除！");
                            $("#dg").datagrid(
                                    "reload");
                        }
                        else {
                            $.messager.alert(
                                    "系统提示",
                                    "数据删除失败！");
                        }
                    },
                    error: function () {
                        $.messager.alert("ERROR！");
                    }
                });
            }
        });
    }
   
    /*驳回*/
    function refuseGood(){
    	var selectedRows = $("#dg").datagrid('getSelections');
        if (selectedRows.length == 0) {
            $.messager.alert("系统提示", "请选择要驳回的商品！");
            return;
        }
    	var id=selectedRows[0].id;//商品id
    	var status=selectedRows[0].status;
    	if(status==2){
    		$.messager.alert("系统提示", "选择的商品已是驳回状态！");
    		return;
    	}
    	
    	var dt={"id":id,"status":2};
    	$.messager.confirm("系统提示", "您确认要驳回？", function (r) {
            if (r) {
                $.ajax({
                    type: "POST",//方法类型
                    dataType: "json",//预期服务器返回的数据类型
                    url: "/goods/update",//url
                    contentType: "application/json; charset=utf-8",
                    data: JSON.stringify(dt),
                    success: function (result) {
                        console.log(result);//打印服务端返回的数据
                        if (result.resultCode == 200) {
                            $("#dg").datagrid("reload");
                        }
                        else {
                            $.messager.alert(
                                    "系统提示",
                                    "驳回失败！");
                        }
                    },
                    error: function () {
                        $.messager.alert("ERROR！");
                    }
                });
            }
        });
    }

    /*通过*/
    function agreeGood(){
    	var selectedRows = $("#dg").datagrid('getSelections');
        if (selectedRows.length == 0) {
            $.messager.alert("系统提示", "请选择要审核通过的商品！");
            return;
        }
        var id=selectedRows[0].id;//商品id
        var status=selectedRows[0].status;
        if(status==1){
            $.messager.alert("系统提示", "选择的商品已是通过状态！");
            return;
        }
        var dt={"id":id,"status":1};
        $.messager.confirm("系统提示", "您确认要审核通过？", function (r) {
            if (r) {
                $.ajax({
                    type: "POST",//方法类型
                    dataType: "json",//预期服务器返回的数据类型
                    url: "/goods/update",//url
                    contentType: "application/json; charset=utf-8",
                    data: JSON.stringify(dt),
                    success: function (result) {
                        console.log(result);//打印服务端返回的数据
                        if (result.resultCode == 200) {
                            $("#dg").datagrid("reload");
                        }
                        else {
                            $.messager.alert(
                                    "系统提示",
                                    "审核通过失败！");
                        }
                    },
                    error: function () {
                        $.messager.alert("ERROR！");
                    }
                });
            }
        });
    }

    function formatProPic(val, row) {
        return "<img width=100 height=100 src='" + val + "'>";
    }
    
    function getTypename(val,row){
    	var typename="";
        $.ajax({
            url:"/goodstype/info/"+row.typeid,
            type:"GET",
            async : false,
            dataType: "json",
            success:function(result){
                 if(result.resultCode==200){
                	 typename=result.data.typename;
                 }
            }
        })
        return '<span>'+typename+'</span>';
    }
    
    function getStatus(val,row){
    	if(val==null){
    		var html1=`<span style="color: blue;">未审核</span>`;
            return html1;
    	}
    	
    	if(val==0){
           var html1=`<span style="color: blue;">未审核</span>`;
           return html1;
        }
    	
    	if(val==1){
    		var html2=`<span style="color: green;">通过</span>`;
    		return html2;
    	}
    	
    	if(val==2){
    		var html3=`<span style="color: red;">驳回</span>`;
    		return html3;
    	}
    }
    
    function formatHref(val, row) {
        var a= `<a style="color:blue" href="Goodsdetail.html?id=${row.id}" target='_blank'>查看详情</a></br>`;
        return a;
    }

    function resetValue() {
        $("#title").val("");
        $("#path").val("");
        $("#title").val("");
        $("#desc").val("");
        $('#picture').find('img').remove();
        $('#pic11').find('input').remove();
        $('#pic11').find('img').remove();
    }

    function closePictureDialog() {
        $("#dlg").dialog("close");
        resetValue();
    }
</script>
</head>

</html>